<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
  <title>成员列表</title>
  <link rel="stylesheet" href="/mobile/css/index.css" />
  <script src="/mobile/js/vue.js"></script>
  <script src="/mobile/js/vue-infinite-scroll.js"></script>
  <script src="/mobile/js/axios.min.js"></script>
  <script src="/mobile/js/vant.min.js"></script>
  <script src="/mobile/js/crypto-js.js"></script>
  <script src="/mobile/js/aes.js"></script>
  <script src="/mobile/js/common.js"></script>
  <style>
  * {
    margin: 0;
    padding: 0;
    -webkit-user-select: none;
    /* Safari */
    -moz-user-select: none;
    /* Firefox */
    -ms-user-select: none;
    /* IE10+/Edge */
    user-select: none;
    /* Standard syntax */
    list-style: none;
  }

  #app {
    padding: 10px;
    background: #05071D;
    min-height: 100vh;
    box-sizing: border-box;
    background-repeat: no-repeat;
    background-position: top center;
    background-size: contain;
  }
  .user-item {
    padding: 10px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #fff;
  }
  .user-item:not(:last-child) {
    border-bottom: 1px solid #1A1C68;
  }

  .user-left {
    display: flex;
  }
  .user-info {
    margin-left: 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
  }
  .user-icon {
    width: 50px;
    height: 50px;
    border-radius: 5px;
    object-fit: cover;
  }
  .user-name {
    font-size: 14px;
    font-weight: bold;
  }
  .user-member {
    font-size: 12px;
  }
  .join-btn {
    height: 30px;
    margin-left: 10px;
  }
  .user-right {
    display: flex;
  }
  .van-empty__image {
    width: 200px;
    height: 150px;
  }

  </style>
</head>

<body>
  <div id="app">
    <template v-if="!list.length">
      <van-empty
        class="custom-image"
        image="/mobile/img/empty.png"
        description="暂无数据"
      />
    </template>
    <div v-else class="user-item" v-for="(item, index) in list" :key="index">
      <div class="user-left">
        <img class="user-icon" :src="item.avatar +'?x-oss-process=image/resize,h_120,m_fill'" alt="">
        <div class="user-info">
          <div class="user-name">{{item.userNickname}}</div>
          <div class="user-member">粉丝数：{{item.fansNum}}</div>
        </div>
      </div>
      <div class="user-right">
        <template v-if="item.manageFlag">
          <van-button class="join-btn" color="#dd378a" round @click="setAdmin(item, 0)">取消管理</van-button>
        </template>
        <template v-else>
          <van-button class="join-btn" color="linear-gradient(270deg, #9358F4 0%, #6E53F3 100%)" round @click="setAdmin(item, 1)">设为管理</van-button>
        </template>
        <van-button class="join-btn" color="#db3c3c" round @click="removeMember(item)">踢出</van-button>
      </div>
    </div>
  </div>
  <script>
  new Vue({
    el: '#app',
    data: {
      id: '',
      token: '',
      list: [],
    },
    created() {
      const parse = (queryStr) => {
        const str = queryStr.replace(/^\?/, '')
        return str.split('&').reduce((pre, key) => {
          const [k, v] = key.split('=')
          pre[decodeURIComponent(k)] = decodeURIComponent(v)
          return pre
        }, {})
      }
      var data = parse(location.search)
      console.log(data)
      if (data.id && data.token) {
        this.id = data.id
        this.token = data.token
        this.getData()
      }
    },
    methods: {
      getData() {
        this.$toast.loading({
          overlay: true,
          forbidClick: true,
          duration: 0
        })
        var query = `id=${this.id}`
        var str = ISCRYPT ? `args=${encrypt(query)}` : query
        request.get(`/api/business/app/family/getInfo?${str}`, {
          headers: {
            token: this.token,
          }
        }).then(res => {
          console.log(res)
          this.list = res.data.users
        }).finally(() => {
          this.$toast.clear()
        })
      },
      removeMember(user) {
        this.$dialog.confirm({
          title: '踢出成员',
          message: `确定将【${user.userNickname}】踢出公会吗?`,
        }).then(() => {
          this.$toast.loading({
            overlay: true,
            forbidClick: true,
            duration: 0
          })
          var query = `uid=${user.uid}`
          var str = ISCRYPT ? `args=${encrypt(query)}` : query
          request.get(`/api/business/app/familyUser/del?${str}`).then(res => {
            this.$toast.clear()
            console.log(res)
            var that = this
            this.$toast({
              message: '操作成功',
              duration: 1500,
              onClose() {
                that.getData()
              }
            })
          }).catch(() => {
            this.$toast.clear()
          })
        }).catch(() => {
          // on cancel
        })
      },
      setAdmin (item, state) {
        var title = state === 0 ? '取消管理' : '设置管理'
        var message = state === 0 ? `确定取消【${item.userNickname}】的公会管理吗?` : `确定将【${item.userNickname}】设置为公会管理吗?`
        this.$dialog.confirm({
          title: title,
          message: message,
        }).then(() => {
          this.$toast.loading({
            overlay: true,
            forbidClick: true,
            duration: 0
          })
          var query = `manageUid=${item.uid}&state=${state}`
          var str = ISCRYPT ? `args=${encrypt(query)}` : query
          request.get(`/api/business/app/family/setManageUid?${str}`).then(res => {
            this.$toast.clear()
            console.log(res)
            var that = this
            this.$toast({
              message: '操作成功',
              duration: 1500,
              onClose() {
                that.getData()
              }
            })
          }).catch(() => {
            this.$toast.clear()
          })
        }).catch(() => {
          // on cancel
        })
      }
    }
  })
  </script>
</body>

</html>